document.write(
    '<script type="text/javascript" src="/adminstatic/js/jquery-3.6.0.min.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/js/jstree.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/js/jquery-3.3.1.min.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/frame/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/plugins/nprogress/nprogress.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/plugins/bootstrap-datetimepicker/moment.min.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/plugins/bootstrap-datetimepicker/locale/zh-cn.js"></script>' +
    '<script type="text/javascript" src="/adminstatic/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>' +
    '<script type="text/javascript" src="/layuiadmin/layui/layui.js"></script>'+
    '<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>'
)

var server = 'http://localhost:8080'

function postJSON(url, data, callback) {
    var index_load = layer.load();
    NProgress.start();
    if ($.isFunction(data)) {
        callback = data;
        data = undefined;
    }
    return $.ajax({
        url: server + url,
        type: "POST",
        data: data,
        success: function (res) {
            callback(res);
            layer.close(index_load);
            NProgress.done();
        },
        dataType: "json",
        error: function (jqXHR, textStatus, errorMsg) {
            layer.msg(errorMsg);
            layer.close(index_load);
            NProgress.done();
        }
    });
}

function postJSONNoIcon(url, data, callback) {
    NProgress.start();
    if ($.isFunction(data)) {
        callback = data;
        data = undefined;
    }
    return $.ajax({
        url: server + url,
        type: "POST",
        data: data,
        success: function (res) {
            callback(res);
            NProgress.done();
        },
        dataType: "json",
        error: function (jqXHR, textStatus, errorMsg) {
            layer.msg(errorMsg);
            NProgress.done();
        }
    });
}

function postNotNProgressJSON(url, data, callback) {
    if ($.isFunction(data)) {
        callback = data;
        data = undefined;
    }
    return $.ajax({
        url: server + url,
        type: "POST",
        data: data,
        success: function (res) {
            callback(res);
        },
        dataType: "json",
        error: function (jqXHR, textStatus, errorMsg) {
            layer.msg(errorMsg);
        }
    });
}

function getJSON(url, data, callback) {
    var index_load = layer.load();

    if ($.isFunction(data)) {
        callback = data;
        data = undefined;
    }
    return $.ajax({
        url: server + url,
        type: "GET",
        data: data,
        success: function (res) {
            callback(res);
            layer.close(index_load)
        },
        dataType: "json",
        error: function (jqXHR, textStatus, errorMsg) {
            alert(errorMsg);
            layer.close(index_load)
        }
    });
}

//关闭弹窗
function closeIframe() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index); //再执行关闭
}

//参数校验
function vaildeParam(param) {
    if (typeof param == 'undefined') {
        return false;
    }
    if (undefined === param) {
        return false
    }
    if (null == param) {
        return false;
    }
    if (param.length === 0) {
        return false;
    }
    return true;
}


function randomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}

/**
 * 随机生成验证码
 * @param codeLength 长度
 * @param codeID    内容
 */
function createCode(codeLength, codeID) {
    // console.log(codeLength,codeID)
    var code = "";
    // 验证码dom元素
    var checkCode = $(codeID);
    // 验证码随机数
    var random = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
        's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
    for (var i = 0; i < codeLength; i++) {
        // 随机数索引
        var index = Math.floor(Math.random() * 62);
        code += random[index];
    }
    // console.log(code)
    // 将生成的随机验证码赋值
    checkCode.val(code);
    // console.log(code)
    localStorage.setItem("code", JSON.stringify(code));
    // console.log(localStorage.getItem("code"));
};

/**
 * 判断手机号是否正确
 * @param mobile
 */
function vaildeMobile(mobile) {
    var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则
    var flag = reg.test(mobile); //true
    console.log(flag)
    if (flag === false) {
        layer.msg("电话格式错误，请重新输入", {icon: 5});
        return;
    }
};

/**
 * 显示列表页面搜索框
 * @param that
 */
function showSearchInputBox(that) {
    var $this = $(that);
    var $listPageHead = $this.parents(".listPageHead");
    var $searchInputBox = $listPageHead.find(".searchInputBox");
    var display = $searchInputBox.css("display");
    if ('none' === display) {
        $searchInputBox.css("display", 'block');
    } else {
        $searchInputBox.css("display", 'none');
    }
}


function getWhereMap($searchInputBox) {
    /** 构造查询条件 */
    var $inputBox = $searchInputBox.find("input");
    var whereMap = {};
    $.each($inputBox, function (index, item) {
        var name = $(item).attr("name");
        var value = $(item).val();
        whereMap[name] = value;
    })
    var $select = $searchInputBox.find("select");
    $.each($select, function (index, item) {
        var name = $(item).attr("name");
        var value = $(item).val();
        whereMap[name] = value;
    })

    return whereMap;
}

function writeObj(obj) {
    var description = "";
    for (var i in obj) {
        var property = obj[i];
        description += i + " = " + property + "\n";
    }
    console.log(description);
}

//点击显示图片
function showimg(e) {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: [$(e).width + 'px', $(e).height + 'px'],
        shade: 0.8,
        shadeClose: true,
        content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + e.src + '">'
    });
}

/**
 * 关闭窗口
 */
function closeIframe() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index); //再执行关闭
}

function cleanSearch() {
    $(".searchInputFilterBox input").val("");
}

function cleanSuccess(res) {
    if ('success' === res.type) {
        layer.msg('操作成功', {icon: 1});
        setTimeout(function () {
            if (vaildeParam(parent)) {
                console.log("关闭父亲窗口对话框")
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.window.location.reload();
            }
        }, 1000)

    } else if ('error' === res.type) {
        layer.msg(res.content, {icon: 5});
    } else {
        layer.msg(res.content, {icon: 5});
    }
}

function  ckeditor(){
    CKEDITOR.replace( 'editor');
}

//上传图片
function uploadImg(elemName, api, id) {
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: elemName //绑定元素
            , multiple: true
            , size: 2048 //文件大小限制
            , number: 1 //文件数量限制
            , acceptMime: 'image/*'
            , ext: 'jpg|png|bmp|jpeg'
            , url: api //上传接口
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.msg('上传中', {icon: 16, time: 0, shade: 0.01});
                obj.preview(function (index, file, result) {
                    // var files = obj.pushFile();
                    console.log(file)
                });
            }
            , done: function (res, index, upload) {
                layer.closeAll('loading');
                if (res.code === 0) {
                    layer.msg(res.msg, {icon: 1});
                    console.log(res.data)
                    $(id).empty();
                    $(id).html('<div class="img-item">' +
                        '<img style="width: 100%;height: 100%;" src="' + res.data + '" onclick="showimg(this)"> ' +
                        '<div class="delete-item" onclick="deleteImg(this)" data-name="' + res.name + '"> ' +
                        '<i class="layui-icon layui-icon-close-fill"></i> ' +
                        '</div> ' +
                        '</div>')
                }

                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                var item = this.item;
                //文件保存失败
                //do something
            }
            , error: function () {
                layer.closeAll('loading');
                //请求异常回调
                layer.msg("上传失败，请重试", {icon: 2});
            }

        });
    });
}

//上传多张图片
function uploadImgList(elemName, api, id) {
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: elemName //绑定元素
            , multiple: true
            , size: 2048 //文件大小限制
            , number: 1 //文件数量限制
            , acceptMime: 'image/*'
            , ext: 'jpg|png|bmp|jpeg'
            , url: api //上传接口
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.msg('上传中', {icon: 16, time: 0, shade: 0.01});
                obj.preview(function (index, file, result) {
                    // var files = obj.pushFile();
                    console.log(file)
                });
            }
            , done: function (res, index, upload) {
                layer.closeAll('loading');
                if (res.code === 0) {
                    layer.msg(res.msg, {icon: 1});
                    console.log(res.data)
                    $(id).append('<div class="img-item">' +
                        '<img style="width: 100%;height: 100%;" src="' + res.data + '" onclick="showimg(this)"> ' +
                        '<div class="delete-item" onclick="deleteImg(this)" data-name="' + res.name + '"> ' +
                        '<i class="layui-icon layui-icon-close-fill"></i> ' +
                        '</div> ' +
                        '</div>')
                }

                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                var item = this.item;
                //文件保存失败
                //do something
            }
            , error: function () {
                layer.closeAll('loading');
                //请求异常回调
                layer.msg("上传失败，请重试", {icon: 2});
            }

        });
    });
}


//点击显示图片
function showimg(e) {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area: ["80%", "80%"],
        shade: 0.8,
        shadeClose: true,
        content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + e.src + '">'
    });
}